home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / NGL2.0.1J(68k).sit / NGL2.0.1J(68k) / Cel & Rotate Sample / Cel & Rotate Sample.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  3KB  |  129 lines

  1. /*============================================================
  2.  
  3.                     Cel & Rotate サンプルプログラム
  4.                     
  5. ============================================================*/
  6. #include        "N_Library.h"
  7.  
  8. short        Data_Rsrc = 0;
  9. long            total_step = 0;
  10. long            wait;
  11. short        i,r=0;
  12. short        x[128];
  13. short        y[128];
  14. short        rt[128];
  15. short        sp[128];
  16.  
  17. void main(void)
  18. {
  19.     WindowPtr    window;
  20.     short        p,xx,yy;
  21.  
  22.     ToolboxInit();
  23.     ColorCheck();
  24.     HideMenuBar();
  25.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  26.     N_Window_Set(window,-(window->portBits.bounds.left),-(window->portBits.bounds.top),640,480);
  27.      Open_Resource_File(128,1,&Data_Rsrc);
  28.     N_Sp_Make(640,480);                                                //スプライト・セルの表示有効範囲
  29.     N_Cel_Make2(640,480);                                                //画面に表示させるセルパターンの総ドット数は最低必要
  30.     HideCursor();
  31.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);
  32.     N_Sprite_Set(129,0,32,32,0,1,1,1);                                    //Sp 0 にパターンを登録(回転付きモード)
  33.     N_Sprite_Set(201,1,32,32,0,1,1,0);                                    //Sp 1 にパターンを登録(背景用)
  34.     N_Sprite_Set(202,2,32,32,0,1,1,0);                                    //Sp 2 にパターンを登録(背景用)
  35.     Delay(60,&wait);
  36.     Close_Resource_File(&Data_Rsrc);
  37.  
  38.     for (i=0;i!=128;i++)                                                    //128個分の初期位置・速度を配列に入れる
  39.     {
  40.         x[i] = GetRandom(0,640-48);
  41.         y[i] = GetRandom(0,480-48);
  42.         sp[i] = GetRandom(2,5)*2;
  43.         rt[i] = 0;
  44.     }
  45.     do
  46.     {
  47.         if (GetRandom(0,1)==0)                                            //乱数で背景を書き換える
  48.         {
  49.             N_Sp_Put(0x80000000+1,GetRandom(0,19)*32,GetRandom(0,14)*32);
  50.         }
  51.         else
  52.         {
  53.             N_Sp_Put(0x80000000+2,GetRandom(0,19)*32,GetRandom(0,14)*32);
  54.         }
  55.     
  56.         if (total_step<128)                                                //1番目の動きは右に移動していく動き
  57.         {
  58.             for (i=0;i!=24;i++)
  59.             {
  60.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,rt[i]);    //中心をそれぞれのパターンの真ん中に設定
  61.                 x[i] = x[i] + sp[i];
  62.                 if (x[i]>640)                                            //右端に行ったら、左に戻り y を変更
  63.                 {
  64.                     x[i] = -64;
  65.                     y[i] = GetRandom(0,480)-48;
  66.                 }
  67.             }
  68.         }
  69.  
  70.         if (total_step>=128 && total_step<256)                                //2番目の動きは、回転
  71.         {
  72.             for (i=0;i!=24;i++)
  73.             {
  74.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],320,240,r);            //(320,240)を中心に角度 r で回転
  75.             }
  76.             r+=8;                                                    //角度を動かす
  77.         }
  78.  
  79.         if (total_step>=256 && total_step<384)                                //3番目の動きは、回転 & 座標移動
  80.         {
  81.             for (i=0;i!=24;i++)
  82.             {
  83.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],300,250,r);            //(300,250)を中心に角度 r で回転
  84.                 x[i] = x[i] + sp[i];
  85.                 if (x[i]>640)                                            //右端に行ったら、左に戻り y を変更
  86.                 {
  87.                     x[i] = -64;
  88.                     y[i] = GetRandom(0,480)-48;
  89.                 }
  90.     
  91.             }
  92.             r-=8;
  93.         }
  94.  
  95.         if (total_step>=384 && total_step<511)                                //4番目の動きは、それぞれの座標を中心にまわりながら右に移動
  96.         {
  97.             for (i=0;i!=24;i++)
  98.             {
  99.                 rt[i] = x[i]*4;
  100.                 N_Cel_2D_Rot_Put(i,0x80000000,x[i],y[i],x[i]+16,y[i]+16,rt[i]);    //中心をそれぞれのパターンの真ん中に設定
  101.                 x[i] = x[i] + sp[i];
  102.                 if (x[i]>640)
  103.                 {
  104.                     x[i] = -64;
  105.                     y[i] = GetRandom(0,480)-48;
  106.                 }
  107.             }
  108.         }
  109.  
  110.         if (total_step == 511)                                            //最初からループ
  111.         {
  112.             total_step =0;
  113.             r = 0;
  114.         }
  115.         
  116.         N_Cel_Loop2(0,0);                                                //画面を更新(N_Sp_Makeで設定した範囲を指定の座標に転送)
  117.         total_step++;
  118.     }
  119.     while (!Button());
  120.  
  121.     ShowMenuBar();
  122.     ShowCursor();
  123.     FlushEvents( everyEvent, 0 ); 
  124.     ColorRevert();
  125. }
  126.  
  127.  
  128.  
  129.